# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=ghex
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.18.4
pkgrel=2
pkgdesc="A simple binary editor for the Gnome desktop (mingw-w64)"
url="https://wiki.gnome.org/Apps/Ghex"
arch=('any')
license=("GPL2")
options=(strip staticlibs)
depends=("${MINGW_PACKAGE_PREFIX}-gtk3")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
install=ghex-${CARCH}.install
source=(https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz
        001-nohelp.patch
        002-fread.patch
        003-gui-app.patch)
sha256sums=('c2d9c191ff5bce836618779865bee4059db81a3a0dff38bda3cc7a9e729637c0'
            '30a351ef0c0b0bc319edec222de5222879b8eecfb58237e5b25c3c1dccf02788'
            '670d0ac95803ea84e53d2d3ee27bd272599c4cab92501426644bfde9fef3d2ae'
            'e48c7c487bc6a4917c91e3bb08f378916e131ee446b0f2f7bd7666a3478a4141')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -Np1 -i ${srcdir}/001-nohelp.patch
  patch -Np1 -i ${srcdir}/002-fread.patch
  patch -Np1 -i ${srcdir}/003-gui-app.patch
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  meson \
    --buildtype=plain \
    -Ddefault_library=both \
    "../${_realname}-${pkgver}"

  ninja
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  DESTDIR=${pkgdir}${MINGW_PREFIX} ninja install

  sed -s "s|$(cygpath -m ${MINGW_PREFIX})|${MINGW_PREFIX}|g" -i "${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/gtkhex-3.pc"

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
